package com.lxp.kotlintest.adapter

import android.content.Intent
import android.view.View
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lxp.kotlintest.R
import com.lxp.kotlintest.bean.news.Data
import com.lxp.kotlintest.view.news.NewsDetailsActivity
import kotlinx.android.synthetic.main.recycler_view_item.view.*
import java.net.URL

class FunctionAdapter(data: MutableList<Data>?) : BaseQuickAdapter<Data, BaseViewHolder>(data), BaseQuickAdapter.OnItemClickListener {


    init {
        mLayoutResId = R.layout.item_news
        setOnItemClickListener(this)
    }

    override fun convert(helper: BaseViewHolder?, item: Data?) {
        helper?.setText(R.id.item_tv_news_title, item?.title)
        helper?.setText(R.id.item_tv_news_time, item?.date)

        Glide.with(mContext)
                .load(item?.thumbnail_pic_s)
                .into(helper?.getView(R.id.item_img_news_pic)!!)

    }

    override fun getItem(position: Int): Data? {
        return super.getItem(position)
    }


    override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
        var it: Intent = Intent(mContext, NewsDetailsActivity::class.java)
        it.putExtra(NewsDetailsActivity.INTENT_NEWS_DETAILS_CODE_URL, getItem(position)?.url)
        mContext.startActivity(it)
    }

}